import { type NextRequest, NextResponse } from "next/server"
import type { ApiResponse } from "@/types"

// 配置为静态路由以支持静态导出
export const dynamic = 'force-static'

export async function POST(request: NextRequest) {
  try {
    // 验证token
    const token = request.headers.get("authorization")?.replace("Bearer ", "")
    if (!token) {
      return NextResponse.json({ success: false, message: "未授权" }, { status: 401 })
    }

    const body = await request.json()

    // 这里应该调用真实的后端API
    // const response = await fetch('http://localhost:8081/api/samples/generate-sampling', {
    //   method: 'POST',
    //   headers: {
    //     'Content-Type': 'application/json',
    //     Authorization: `Bearer ${token}`
    //   },
    //   body: JSON.stringify(body)
    // })
    // const result = await response.json()
    // return NextResponse.json(result)

    const { mixedNumbers } = body

    if (!mixedNumbers || !Array.isArray(mixedNumbers) || mixedNumbers.length === 0) {
      return NextResponse.json({ success: false, message: "请选择要生成抽检编号的混合编号组" }, { status: 400 })
    }

    // 临时模拟响应，实际项目中应该删除
    const samplingNumber = `SP${String(Date.now()).slice(-3)}`

    const response: ApiResponse<void> = {
      success: true,
      message: `成功生成抽检编号 ${samplingNumber}`,
    }

    return NextResponse.json(response)
  } catch (error) {
    return NextResponse.json({ success: false, message: "服务器错误" }, { status: 500 })
  }
}
